package model;

import java.util.ArrayList;

public class CalcItem {

	private final ArrayList<Term> termList = new ArrayList<Term>();

	public final String termId;
	public final String originalTerm;
	private final Term currentTerm;
	//private final String optimizedTerm;

	public CalcItem(String termId, String term, String descr, String theme) {
		this.termId = termId;
		originalTerm = StringAnalyser.getOptimizedTerm(term);
		currentTerm = new Term(originalTerm, descr, theme);
		termList.add(currentTerm);
	}

	@Override
	public String toString() {
		return termId + " = " + currentTerm.toString();
	}

	public Value calc(ArrayList valueList) {
		/*
		 * the problem is, that the order of the vars might change in new terms
		 * but the order of the values is static so the new term gets the old
		 * order of the terms
		 * 
		 * eg:
		 * x=y+z (input y=6,z=7)
		 * is changed to x=z+y
		 * but the input is still (input y=6,z=7) and not z=6,y=7 !!
		 */
		VarValueList varValueList = new VarValueList(originalTerm, valueList);
		currentTerm.executeOn(varValueList);
		return varValueList.idValue;
	}

	public int speedCalc(ArrayList intValueList) {
		SpeedVarValueList speedVarValueList = new SpeedVarValueList(originalTerm, intValueList);
		currentTerm.executeOn(speedVarValueList);
		return speedVarValueList.idValue;
	}

}